using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VZOLLEAN
    {
        public DataRow Convert2ZOLLEAN(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryZOLLEAN(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["ZOMANDANT"] = " ".PadRight(2 ); 
         dwReturn["ZOARTST"] = " ".PadRight(1 ); 
         dwReturn["ZOKUNDNRKO"] = " ".PadRight(8 ); 
         dwReturn["ZOWERK"] = " ".PadRight(3 ); 
         dwReturn["ZOABT"] = " ".PadRight(3 ); 
         dwReturn["ZOART"] = " ".PadRight(24 ); 
         dwReturn["ZOVAR"] = " ".PadRight(3 ); 
         dwReturn["ZOFARBE"] = " ".PadRight(10 ); 
         dwReturn["ZODESSGROE"] = " ".PadRight(10 ); 
         dwReturn["ZOCOLAM"] = " ".PadRight(10 ); 
         dwReturn["ZOBESCHVP"] = " ".PadRight(10 ); 
         dwReturn["ZOKDLIEFKZ"] = " ".PadRight(1 ); 
         dwReturn["ZOKDLIEFNR"] = " ".PadRight(8 ); 
         dwReturn["ZOAENZL"] = " ".PadRight(0 ); 
         dwReturn["ZOAENB"] = " ".PadRight(8 ); 
         dwReturn["ZOAEND"] = " ".PadRight(0 ); 
         dwReturn["ZONEUB"] = " ".PadRight(8 ); 
         dwReturn["ZONEUD"] = " ".PadRight(0 ); 
         dwReturn["ZOMATCHCODE"] = " ".PadRight(24 ); 
         dwReturn["ZOZOLLTNR"] = " ".PadRight(20 ); 
         dwReturn["ZOEAN"] = " ".PadRight(13 ); 
         dwReturn["ZOEAN2"] = " ".PadRight(5 ); 
         dwReturn["ZOEXTART"] = " ".PadRight(30 ); 
         dwReturn["ZOARTAVV"] = " ".PadRight(20 ); 
         dwReturn["ZOPREIS1"] = " ".PadRight(0 ); 
         dwReturn["ZOWAEHRSL1"] = " ".PadRight(3 ); 
         dwReturn["ZOPREIS2"] = " ".PadRight(0 ); 
         dwReturn["ZOWAEHRSL2"] = " ".PadRight(3 ); 
         dwReturn["ZOURLAND"] = " ".PadRight(3 ); 
         dwReturn["ZOUEBKZ"] = " ".PadRight(1 ); 
         dwReturn["ZOVERZKZ"] = " ".PadRight(1 ); 
         dwReturn["ZOBEWNR"] = " ".PadRight(15 ); 
         dwReturn["ZOBEWDAT"] = " ".PadRight(0 ); 
         dwReturn["ZOBISDAT"] = " ".PadRight(0 ); 
         dwReturn["ZOLAGERNR"] = " ".PadRight(10 ); 
         dwReturn["ZOMAXWERT"] = " ".PadRight(0 ); 
         dwReturn["ZOMAXMENGE"] = " ".PadRight(0 ); 
         dwReturn["ZOMAXME"] = " ".PadRight(1 ); 
         dwReturn["ZOAMT"] = " ".PadRight(6 ); 
         dwReturn["ZOMINPRKZ"] = " ".PadRight(1 ); 
         dwReturn["ZOVARKZ"] = " ".PadRight(1 ); 
         dwReturn["ZOTRBUCH"] = " ".PadRight(1 ); 
         dwReturn["ZOGENEHMKZ"] = " ".PadRight(1 ); 
         dwReturn["ZOZTNRUSA"] = " ".PadRight(20 ); 
         dwReturn["ZOHSURLAND"] = " ".PadRight(3 ); 
         dwReturn["ZOMEEH"] = " ".PadRight(3 ); 
         dwReturn["ZOFBBEZ"] = " ".PadRight(20 ); 
         dwReturn["ZODCBEZ"] = " ".PadRight(20 ); 
         dwReturn["ZOBEBEZ"] = " ".PadRight(20 ); 
         dwReturn["ZOFILLER"] = " ".PadRight(62 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapZOLLEAN(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveZOLLEAN(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryZOLLEAN(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapZOLLEAN(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertZOLLEAN(dwLocal, ITXDBVERSION);
            }
            UpdateZOLLEAN(dwLocal);
        }
        public void InsertZOLLEAN(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO ZOLLEAN(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryZOLLEAN(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM ZOLLEAN WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM ZOLLEAN  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "ZOLLEAN";
            Return = Result;
            return Return;
        }
        public void DeleteZOLLEAN(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM ZOLLEAN   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateZOLLEAN(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE ZOLLEAN SET "
                    +"ZOMANDANT= :ZOMANDANT,"
                    +"ZOARTST= :ZOARTST,"
                    +"ZOKUNDNRKO= :ZOKUNDNRKO,"
                    +"ZOWERK= :ZOWERK,"
                    +"ZOABT= :ZOABT,"
                    +"ZOART= :ZOART,"
                    +"ZOVAR= :ZOVAR,"
                    +"ZOFARBE= :ZOFARBE,"
                    +"ZODESSGROE= :ZODESSGROE,"
                    +"ZOCOLAM= :ZOCOLAM,"
                    +"ZOBESCHVP= :ZOBESCHVP,"
                    +"ZOKDLIEFKZ= :ZOKDLIEFKZ,"
                    +"ZOKDLIEFNR= :ZOKDLIEFNR,"
                    +"ZOAENZL= :ZOAENZL,"
                    +"ZOAENB= :ZOAENB,"
                    +"ZOAEND= :ZOAEND,"
                    +"ZONEUB= :ZONEUB,"
                    +"ZONEUD= :ZONEUD,"
                    +"ZOMATCHCODE= :ZOMATCHCODE,"
                    +"ZOZOLLTNR= :ZOZOLLTNR,"
                    +"ZOEAN= :ZOEAN,"
                    +"ZOEAN2= :ZOEAN2,"
                    +"ZOEXTART= :ZOEXTART,"
                    +"ZOARTAVV= :ZOARTAVV,"
                    +"ZOPREIS1= :ZOPREIS1,"
                    +"ZOWAEHRSL1= :ZOWAEHRSL1,"
                    +"ZOPREIS2= :ZOPREIS2,"
                    +"ZOWAEHRSL2= :ZOWAEHRSL2,"
                    +"ZOURLAND= :ZOURLAND,"
                    +"ZOUEBKZ= :ZOUEBKZ,"
                    +"ZOVERZKZ= :ZOVERZKZ,"
                    +"ZOBEWNR= :ZOBEWNR,"
                    +"ZOBEWDAT= :ZOBEWDAT,"
                    +"ZOBISDAT= :ZOBISDAT,"
                    +"ZOLAGERNR= :ZOLAGERNR,"
                    +"ZOMAXWERT= :ZOMAXWERT,"
                    +"ZOMAXMENGE= :ZOMAXMENGE,"
                    +"ZOMAXME= :ZOMAXME,"
                    +"ZOAMT= :ZOAMT,"
                    +"ZOMINPRKZ= :ZOMINPRKZ,"
                    +"ZOVARKZ= :ZOVARKZ,"
                    +"ZOTRBUCH= :ZOTRBUCH,"
                    +"ZOGENEHMKZ= :ZOGENEHMKZ,"
                    +"ZOZTNRUSA= :ZOZTNRUSA,"
                    +"ZOHSURLAND= :ZOHSURLAND,"
                    +"ZOMEEH= :ZOMEEH,"
                    +"ZOFBBEZ= :ZOFBBEZ,"
                    +"ZODCBEZ= :ZODCBEZ,"
                    +"ZOBEBEZ= :ZOBEBEZ,"
                    +"ZOFILLER= :ZOFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("ZOMANDANT", OracleType.NVarChar).Value = dwData["ZOMANDANT"].ToString(); 
          or1.Parameters.Add("ZOARTST", OracleType.NVarChar).Value = dwData["ZOARTST"].ToString(); 
          or1.Parameters.Add("ZOKUNDNRKO", OracleType.NVarChar).Value = dwData["ZOKUNDNRKO"].ToString(); 
          or1.Parameters.Add("ZOWERK", OracleType.NVarChar).Value = dwData["ZOWERK"].ToString(); 
          or1.Parameters.Add("ZOABT", OracleType.NVarChar).Value = dwData["ZOABT"].ToString(); 
          or1.Parameters.Add("ZOART", OracleType.NVarChar).Value = dwData["ZOART"].ToString(); 
          or1.Parameters.Add("ZOVAR", OracleType.NVarChar).Value = dwData["ZOVAR"].ToString(); 
          or1.Parameters.Add("ZOFARBE", OracleType.NVarChar).Value = dwData["ZOFARBE"].ToString(); 
          or1.Parameters.Add("ZODESSGROE", OracleType.NVarChar).Value = dwData["ZODESSGROE"].ToString(); 
          or1.Parameters.Add("ZOCOLAM", OracleType.NVarChar).Value = dwData["ZOCOLAM"].ToString(); 
          or1.Parameters.Add("ZOBESCHVP", OracleType.NVarChar).Value = dwData["ZOBESCHVP"].ToString(); 
          or1.Parameters.Add("ZOKDLIEFKZ", OracleType.NVarChar).Value = dwData["ZOKDLIEFKZ"].ToString(); 
          or1.Parameters.Add("ZOKDLIEFNR", OracleType.NVarChar).Value = dwData["ZOKDLIEFNR"].ToString(); 
          or1.Parameters.Add("ZOAENZL", OracleType.NVarChar).Value = dwData["ZOAENZL"].ToString(); 
          or1.Parameters.Add("ZOAENB", OracleType.NVarChar).Value = dwData["ZOAENB"].ToString(); 
          or1.Parameters.Add("ZOAEND", OracleType.NVarChar).Value = dwData["ZOAEND"].ToString(); 
          or1.Parameters.Add("ZONEUB", OracleType.NVarChar).Value = dwData["ZONEUB"].ToString(); 
          or1.Parameters.Add("ZONEUD", OracleType.NVarChar).Value = dwData["ZONEUD"].ToString(); 
          or1.Parameters.Add("ZOMATCHCODE", OracleType.NVarChar).Value = dwData["ZOMATCHCODE"].ToString(); 
          or1.Parameters.Add("ZOZOLLTNR", OracleType.NVarChar).Value = dwData["ZOZOLLTNR"].ToString(); 
          or1.Parameters.Add("ZOEAN", OracleType.NVarChar).Value = dwData["ZOEAN"].ToString(); 
          or1.Parameters.Add("ZOEAN2", OracleType.NVarChar).Value = dwData["ZOEAN2"].ToString(); 
          or1.Parameters.Add("ZOEXTART", OracleType.NVarChar).Value = dwData["ZOEXTART"].ToString(); 
          or1.Parameters.Add("ZOARTAVV", OracleType.NVarChar).Value = dwData["ZOARTAVV"].ToString(); 
          or1.Parameters.Add("ZOPREIS1", OracleType.NVarChar).Value = dwData["ZOPREIS1"].ToString(); 
          or1.Parameters.Add("ZOWAEHRSL1", OracleType.NVarChar).Value = dwData["ZOWAEHRSL1"].ToString(); 
          or1.Parameters.Add("ZOPREIS2", OracleType.NVarChar).Value = dwData["ZOPREIS2"].ToString(); 
          or1.Parameters.Add("ZOWAEHRSL2", OracleType.NVarChar).Value = dwData["ZOWAEHRSL2"].ToString(); 
          or1.Parameters.Add("ZOURLAND", OracleType.NVarChar).Value = dwData["ZOURLAND"].ToString(); 
          or1.Parameters.Add("ZOUEBKZ", OracleType.NVarChar).Value = dwData["ZOUEBKZ"].ToString(); 
          or1.Parameters.Add("ZOVERZKZ", OracleType.NVarChar).Value = dwData["ZOVERZKZ"].ToString(); 
          or1.Parameters.Add("ZOBEWNR", OracleType.NVarChar).Value = dwData["ZOBEWNR"].ToString(); 
          or1.Parameters.Add("ZOBEWDAT", OracleType.NVarChar).Value = dwData["ZOBEWDAT"].ToString(); 
          or1.Parameters.Add("ZOBISDAT", OracleType.NVarChar).Value = dwData["ZOBISDAT"].ToString(); 
          or1.Parameters.Add("ZOLAGERNR", OracleType.NVarChar).Value = dwData["ZOLAGERNR"].ToString(); 
          or1.Parameters.Add("ZOMAXWERT", OracleType.NVarChar).Value = dwData["ZOMAXWERT"].ToString(); 
          or1.Parameters.Add("ZOMAXMENGE", OracleType.NVarChar).Value = dwData["ZOMAXMENGE"].ToString(); 
          or1.Parameters.Add("ZOMAXME", OracleType.NVarChar).Value = dwData["ZOMAXME"].ToString(); 
          or1.Parameters.Add("ZOAMT", OracleType.NVarChar).Value = dwData["ZOAMT"].ToString(); 
          or1.Parameters.Add("ZOMINPRKZ", OracleType.NVarChar).Value = dwData["ZOMINPRKZ"].ToString(); 
          or1.Parameters.Add("ZOVARKZ", OracleType.NVarChar).Value = dwData["ZOVARKZ"].ToString(); 
          or1.Parameters.Add("ZOTRBUCH", OracleType.NVarChar).Value = dwData["ZOTRBUCH"].ToString(); 
          or1.Parameters.Add("ZOGENEHMKZ", OracleType.NVarChar).Value = dwData["ZOGENEHMKZ"].ToString(); 
          or1.Parameters.Add("ZOZTNRUSA", OracleType.NVarChar).Value = dwData["ZOZTNRUSA"].ToString(); 
          or1.Parameters.Add("ZOHSURLAND", OracleType.NVarChar).Value = dwData["ZOHSURLAND"].ToString(); 
          or1.Parameters.Add("ZOMEEH", OracleType.NVarChar).Value = dwData["ZOMEEH"].ToString(); 
          or1.Parameters.Add("ZOFBBEZ", OracleType.NVarChar).Value = dwData["ZOFBBEZ"].ToString(); 
          or1.Parameters.Add("ZODCBEZ", OracleType.NVarChar).Value = dwData["ZODCBEZ"].ToString(); 
          or1.Parameters.Add("ZOBEBEZ", OracleType.NVarChar).Value = dwData["ZOBEBEZ"].ToString(); 
          or1.Parameters.Add("ZOFILLER", OracleType.NVarChar).Value = dwData["ZOFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
